<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
      parent<child></child>
    </div>
    <script src="vue.js"></script>
    <script>
        var vm = new Vue({
            el:'#app',
            provide:{
                name:'parent',
                sayHello(){
                    console.log(`sayHello`)
                }
            },
            components:{
                child:{
                    inject:['name'],
                    template:'<div>child{{name}}<grandson></grandson></div>',
                    components:{
                        grandson:{
                            inject:['sayHello'],
                            template:`<div @click="sayHello">grandson</div>`
                        }
                    }
                }
            }
        });
    </script>
</body>
</html>